//
//  YSPMSPeopleInfoCell.m
//  YaSha-iOS
//
//  Created by YaSha_Tom on 2017/8/31.
//
//

#import "YSPMSPeopleInfoCell.h"

@interface YSPMSPeopleInfoCell()

@property(nonatomic,strong)UIImageView *headerImage;
@property(nonatomic,strong)UILabel *nameLabel;
@property(nonatomic,strong)QMUIButton *noButton;
@property(nonatomic,strong)QMUIButton *startButton;
@property(nonatomic,strong)QMUIButton *endButton;


@end

@implementation YSPMSPeopleInfoCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
    
}

- (void)initUI {
    self.headerImage = [[UIImageView alloc]init];
    self.headerImage.layer.masksToBounds = YES;
    self.headerImage.layer.cornerRadius = 18*kWidthScale;
    [self.contentView addSubview:self.headerImage];
    [self.headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).offset(16*kHeightScale);
        make.left.mas_equalTo(self.contentView.mas_left).offset(22*kWidthScale);
        make.size.mas_equalTo(CGSizeMake(36*kWidthScale, 36*kHeightScale));
    }];
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = [UIFont systemFontOfSize:16];
    self.nameLabel.textColor = [UIColor blackColor];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.textColor = [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.headerImage.mas_bottom).offset(5);
        make.left.mas_equalTo(self.contentView.mas_left).offset(5*kWidthScale);
        make.size.mas_equalTo(CGSizeMake(70*kWidthScale, 16*kHeightScale));
        make.bottom.mas_equalTo(-10).priority(100);
    }];
    
    self.noButton = [[QMUIButton alloc]init];
    self.noButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.noButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.contentView addSubview:self.noButton];
    [self.noButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).offset(10);
        make.left.mas_equalTo(self.headerImage.mas_right).offset(25*kWidthScale);
        make.size.mas_equalTo(CGSizeMake(150*kWidthScale, 20*kHeightScale));
    }];
    
    self.phoneButton = [[QMUIButton alloc]init];
    self.phoneButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.phoneButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.contentView addSubview:self.phoneButton];
    [self.phoneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.noButton.mas_bottom).offset(5);
        make.left.mas_equalTo(self.headerImage.mas_right).offset(25*kWidthScale);
        make.size.mas_equalTo(CGSizeMake(150*kWidthScale, 20*kHeightScale));
    }];

    
    
    self.startButton = [[QMUIButton alloc]init];
    self.startButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.startButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.contentView addSubview:self.startButton];
    [self.startButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.phoneButton.mas_bottom).offset(5);
        make.left.mas_equalTo(self.headerImage.mas_right).offset(25*kWidthScale);
        make.size.mas_equalTo(CGSizeMake(150*kWidthScale, 20*kHeightScale));
    }];
    
    
    
}

- (void)setPeopleInfoCell:(ProjectPeopleModel *)cellModel {

 
    self.headerImage.image = [UIImage imageNamed:@"人员信息-头像"];
    self.nameLabel.text = cellModel.name;
    //工号
    [self.noButton setImage:[UIImage imageNamed:@"工号"] forState:UIControlStateNormal];
    [self.noButton setTitle:cellModel.code forState:UIControlStateNormal];
    self.noButton.imagePosition = QMUIButtonImagePositionLeft;
    self.noButton.spacingBetweenImageAndTitle = 10;
    //电话号码
    [self.phoneButton setImage:[UIImage imageNamed:@"电话"] forState:UIControlStateNormal];
    [self.phoneButton setTitle:cellModel.mobile forState:UIControlStateNormal];
    self.phoneButton.imagePosition = QMUIButtonImagePositionLeft;
    self.phoneButton.spacingBetweenImageAndTitle = 11;
    
    if (cellModel.enterDate.length > 0) {
        self.startButton.hidden = NO;
        [self.startButton setImage:[UIImage imageNamed:@"进场"] forState:UIControlStateNormal];
        [self.startButton setTitle:@"2018-11-30" forState:UIControlStateNormal];
        self.startButton.imagePosition = QMUIButtonImagePositionLeft;
        self.startButton.spacingBetweenImageAndTitle = 8;
        [self.startButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.phoneButton.mas_bottom).offset(5);
            make.left.mas_equalTo(self.headerImage.mas_right).offset(25*kWidthScale);
            make.size.mas_equalTo(CGSizeMake(150*kWidthScale, 20*kHeightScale));
        }];
    }else {
        self.startButton.hidden = YES;
        [self.startButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.phoneButton.mas_bottom).offset(0);
            make.left.mas_equalTo(self.headerImage.mas_right).offset(25*kWidthScale);
            make.size.mas_equalTo(CGSizeMake(0*kWidthScale, 0*kHeightScale));
        }];
    }
}
@end
